package com.jjb.common.task.event;


import com.jjb.common.task.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class TaskEventListener implements ApplicationListener<TaskEvent> {

    private ExecutorService executors = Executors.newFixedThreadPool(20);

    @Autowired
    private TaskService taskService;

    @Override
    public void onApplicationEvent(TaskEvent event) {
        executors.submit(() -> {
            taskService.execById(event.getMessageTask().getId());
        });
    }
}
